﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace sp.netWebFroms
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lblcommet.Text = "";
            }
        }


        protected void btnlogin_Click(object sender, EventArgs e)
        {
            var uid = txtUsername.Text.Trim();
            var pwd = txtPassword.Text.Trim();

            var sql = string.Format("select * from Users where Username='{0}'", uid);
            var dt = DbHelp.GetData(sql);
            if (dt.Rows.Count == 1)
            {
                var item = dt.Rows[0];
                var password = item.ItemArray[2].ToString();
                var isActived = (bool)item.ItemArray[3];
                var isDeleted = (bool)item.ItemArray[4];
             
                if(isDeleted)
                {
                    lblcommet.Text = "当前账号已被删除，请联系网站管理人员";
                }
                else
                {
                    if(isActived)
                    {
                        if(pwd==password)
                        {
                            Response.Redirect("Default.aspx");
                        }
                    }
                    else
                    {
                        lblcommet.Text = "用户名或者密码错误，请重新尝试登陆";
                    }
                    
                }
                
            }
            else
            {
                lblcommet.Text = "该账户已被冻结请联系网站管理人员";
            }
           
        }
        
    }
}
